//
//  PackageCell.m
//  ForestPack
//
//  Created by 骆锴 on 2018/7/18.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "PackageCell.h"

@interface PackageCell ()

@property (nonatomic, strong) UIView *headView;
@property (nonatomic, strong) UIImageView *headImage;
@property (nonatomic, strong) UIView *fonterview;
@property (nonatomic, strong) UILabel *fonterContent;
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UILabel *weight;
@property (nonatomic, strong) UILabel *price;
@property (nonatomic, strong) UILabel *line;

@end

@implementation PackageCell

+ (PackageCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"PackageCell";
    PackageCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[PackageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.backgroundColor = [UIColor whiteColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    _headView = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(12), 0, ScreenX375(143), ScreenX375(115))];
    
    _headImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(1), ScreenX375(15), ScreenX375(140), ScreenX375(78))];
    _headImage.layer.cornerRadius = 5.0;
    _headImage.clipsToBounds = YES;
    _headImage.contentMode = UIViewContentModeScaleAspectFill;
    [_headView addSubview:_headImage];
    
    _line = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(108), ScreenX375(349), ScreenX375(1))];
    UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"虚线"]];
    [_line setBackgroundColor:color];
    [self addSubview:_line];
    
//    _fonterview =[[UIView alloc] initWithFrame:CGRectMake(-13, ScreenX375(62), ScreenX375(174), ScreenX375(22))];
//    _fonterview.backgroundColor = ThemeColor;
//    _fonterview.clipsToBounds = YES;
//    
//    _fonterContent = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(25), ScreenX375(1), ScreenX375(115), ScreenX375(15))];
//    _fonterContent.textColor = [UIColor whiteColor];
//    _fonterContent.font = Kfont(12.0);
//    _fonterContent.text = @"活动倒计时 22:03:59";
//    _fonterContent.textAlignment = NSTextAlignmentCenter;
//    [_fonterview addSubview:_fonterContent];
//    [_headImage addSubview:_fonterview];
    [_headView addSubview:_headImage];
    [self addSubview:_headView];
    
    _title = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(164), ScreenX375(16), SCREEN_WIDTH - ScreenX375(190), ScreenX375(13))];
    _title.textAlignment = NSTextAlignmentLeft;
    _title.textColor = RGBACOLOR(51, 51, 51, 1);
    _title.font = Kfont(14.0);
    [self addSubview:_title];
    
    _weight = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(164), ScreenX375(40),ScreenX375(193) , ScreenX375(13))];
    _weight.textAlignment = NSTextAlignmentLeft;
    _weight.textColor = RGBACOLOR(102, 102, 102, 1);
    _weight.font = [UIFont systemFontOfSize:12.0];
    [self addSubview:_weight];
    
    _price = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(113), ScreenX375(81),ScreenX375(100) , ScreenX375(13))];
    _price.textAlignment = NSTextAlignmentRight;
    _price.textColor = ThemeColor;
    _price.font = [UIFont systemFontOfSize:12.0];
    [self addSubview:_price];
}

- (void)initWithModel:(PackageListModel *)model {
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:model.index_pic] placeholderImage:nil options:SDWebImageRetryFailed];
    self.title.text = model.goods_name;
    self.price.text = [NSString stringWithFormat:@"%@元",model.price];
    self.weight.text = [NSString stringWithFormat:@"克重: (%@)g",model.weight];
}
- (void)initWithCardModel:(CHCardItemModel *)model {
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:model.index_pic] placeholderImage:nil options:SDWebImageRetryFailed];
    self.title.text = model.card_name;
    self.price.text = [NSString stringWithFormat:@"%@元",model.price];
//    self.weight.text = [NSString stringWithFormat:@"克重: (%@)g",model.weight];
}

@end

@implementation PackageListModel

@end
